package com.xez.data
{
	import flash.utils.ByteArray;

	[Bindable]
	public class User extends CacheData
	{
		public var username:String;
		public var password:String;
		public var isvip:Boolean = false;
		public var isboss:Boolean = false;
		public var islogin:Boolean = false;
		public var dec:String;
		
		override public function get cachename():String
		{
			return 'user';
		}
		
		public function save():void
		{
			var obj:Object = new Object();
			obj.username = username;
			obj.password = password;
			obj.isvip = isvip;
			obj.isboss = isboss;
			obj.islogin = islogin;
			
			var bytes:ByteArray = new ByteArray();
			bytes.writeObject(obj);
			saveCache(bytes);
		}
		
		public function getFromLocal():void
		{
			var bytes:ByteArray = getCache();
			if (bytes)
			{
				var obj:Object = bytes.readObject();
				username = obj.username;
				password = obj.password;
				isvip = obj.isvip;
				isboss = obj.isboss;
				islogin = obj.islogin;
				
				setDec();
			}
		}
		
		public function setDec():void
		{
			if (isboss)
				dec = '管理员';
			else if (isvip)
				dec = 'VIP会员';
			else
				dec = '普通用户';
		}
		
		
	}
}